<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="800px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{$t('sys.execution_record')}}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <div class="pl30 pr30">
      <el-table
        ref="table"
        :data="tableData"
        style="width: 100%"
        current-row-key="id"
        stripe
        border
        v-loading="loading"
      >
        <el-table-column prop="version" label="#" width="48">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="title" :label="$t('sys.run_SQL')">
          <template slot-scope="scope">
            <span :title="scope.row.sql">{{ scope.row.sql }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" :label="$t('sys.error_message')">
          <template slot-scope="scope">
            <span :title="scope.row.errorInfo || $t('sys.none')">{{
              scope.row.errorInfo || $t('sys.none')
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" :label="$t('sys.running_time')" width="150">
          <template slot-scope="scope">
            <span
              :title="
                moment(scope.row.createDate).format('YYYY-MM-DD HH:mm:ss')
              "
            >{{
              moment(scope.row.createDate).format('YYYY-MM-DD HH:mm:ss')
            }}</span
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="tr mt24">
        <x-pagination
          :total="total"
          :pageSize.sync="pageData.pageSize"
          :pageNo.sync="pageData.pageNo"
          @search="loadHistory()"
        />
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getWebsqlexecutehistoryPagelist } from '@/apis/paas/HmWebSqlExecuteHistoryController.js'
import { decode } from 'js-base64'
import moment from 'moment'
export default {
  data () {
    return {
      loading: false,
      showVisible: false,
      pageData: {
        pageSize: 10,
        pageNo: 1
      },
      total: 0,
      tableData: [],
      options: {}
    }
  },

  methods: {
    decode,
    moment,
    open (options = {}) {
      this.tableData = []
      this.pageData = {
        pageSize: 10,
        pageNo: 1
      }
      this.showVisible = true
      this.options = { ...options }
      this.loadHistory()
    },

    close () {
      this.showVisible = false
    },

    async loadHistory (pageNo = this.pageData.pageNo) {
      const res = await getWebsqlexecutehistoryPagelist({
        ...this.pageData,
        pageNo
      })
      this.tableData = res.data
      this.total = res.totalCount
      this.pageData = {
        pageSize: res.pageSize,
        pageNo: res.pageNo
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
